{% extends "base.html" %}
{% import "bootstrap/wtf.html" as wtf %}
{% import "_macros.html" as macros %}

{% block title %}语音识别模型基准测试系统{% endblock %}

{% block page_content %}
<div class="page-header">
    {% if is_searched %}
    <p>{{ kw }}搜索结果共有{{ fpfes.total }}条语音的前端处理器和特征提取器数据项</p>
    <a class="btn btn-default" href="{{ url_for('/.fpfe') }}">查看所有语音的前端处理器和特征提取器信息</a>
    {% else %}
    <p>目前共有{{ fpfes.total }}条语音的前端处理器和特征处理器数据项</p>
    <a class="btn btn-default" href="{{ url_for('.fpfe_add') }}">新增语音的前端处理器和特征提取器信息</a>
    {% endif %}
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <input type="text" id="kw-input" onkeyup="update_action(event,this.value)" value="{{ kw }}"><a class="btn btn-default" id="search-a" href="{{ url_for('.fpfe_search',kw='') }}">搜索</a>
    <p>筛选条件：</p>
    <p>类型：<input type="checkbox" id="fp-search">语音的前端处理器&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="fe-search">语音的特征提取器&nbsp;&nbsp;&nbsp;&nbsp;<input type="checkbox" id="fp-fp-search">语音的前端处理器+语音的特征提取器</p>
    {% if fpfes.first==0 %}
    <p>没有{% if kw %}含有{{ kw }}的{% endif %}语音的前端处理器和特征提取器信息</p>
    {% else %}
    <div class="row">
    <table class="table">
        <thead>
        <tr>
            <th>名称</th>
            <th>类型</th>
            <th>模块名</th>
            <th>模块的全局函数名</th>
            <th>全局函数的参数列表</th>
            <th>[函数名(参数列表)]</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
        {% for fpfe in fpfes.items %}
        <tr>
            <td class="content-td">{{ fpfe.name }}</td>
            <td>{% if fpfe.typ==0 %}前端处理器{% elif fpfe.typ==1 %}特征提取器{% elif fpfe.typ==2 %}前端处理器+特征提取器{% endif %}</td>
            <td class="content-td">{{ fpfe.modulename }}</td>
            <td class="content-td">
                {{ fpfe.classname }}
            </td>
            <td class="content-td">{{ fpfe.parameters }}</td>
            <td class="content-td">{{ fpfe.attribute }}</td>
            <td>
                <a class="btn btn-default" href="{{ url_for('.ff',id=fpfe.id) }}">详情</a>
                <a class="btn btn-default" href="{{ url_for('.fpfe_edit',id=fpfe.id) }}">修改</a>
                <a class="btn btn-default" href="{{ url_for('.fpfe_delete',id=fpfe.id,page=page,per_page=per_page) }}">删除</a>
                <a class="btn btn-default" href="{{ url_for('.fpfe_json',id=fpfe.id) }}">导出语音的前端处理器和特征提取器的json配置文件</a>
                <a class="btn btn-default" href="{{ url_for('.fpfe_active',id=fpfe.id) }}">更新活动时间</a>
                <a class="btn btn-default" href="{{ url_for('.fpfe_copy',id=fpfe.id) }}">以此为模版新建</a>
            </td>
        </tr>
        {% endfor %}
        </tbody>
        <tfoot>
            {% if is_searched %}
            <tr>
                <td colspan="4">
                    <ul class="pagination">
                        {% for i in page_range %}
                        {% if i==fpfes.page %}
                        <li class="active"><a href="/fpfe_search?page={{ i }}&per_page={{ per_page }}&{{ params }}">{{ i }}</a></li>
                        {% else %}
                        <li><a href="/fpfe_search?page={{ i }}&per_page={{ per_page }}&{{ params }}">{{ i }}</a></li>
                        {% endif %}
                        {% endfor %}
                    </ul>
                </td>
                <td colspan="3" style="vertical-align:bottom">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">当前每页{{ per_page }}条数据项，更改至每页数据项 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            {% for i in [5,10,20,50] %}
                            <li><a href="/fpfe_search?page=1&per_page={{ i }}&{{ params }}">{{ i }}条</a></li>
                            {% endfor %}
                        </ul>
                    </li>
                </td>
            </tr>
            {% else %}
            <tr>
                <td colspan="4">
                    <ul class="pagination">
                        {% for i in page_range %}
                        {% if i==fpfes.page %}
                        <li class="active"><a href="/fpfe?page={{ i }}&per_page={{ per_page }}">{{ i }}</a></li>
                        {% else %}
                        <li><a href="/fpfe?page={{ i }}&per_page={{ per_page }}">{{ i }}</a></li>
                        {% endif %}
                        {% endfor %}
                    </ul>
                </td>
                <td colspan="3" style="vertical-align:bottom">
                    <li class="dropdown">
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">当前每页{{ per_page }}条数据项，更改至每页数据项 <b class="caret"></b></a>
                        <ul class="dropdown-menu">
                            {% for i in [5,10,20,50] %}
                            <li><a href="/fpfe?page=1&per_page={{ i }}">{{ i }}条</a></li>
                            {% endfor %}
                        </ul>
                    </li>
                </td>
            </tr>
            {% endif %}
        </tfoot>
    </table>
</div>
    {% endif %}
    <p id="kw-value" style="display:none">{{ kw }}</p>
<script type="text/javascript">
    function update_action(event,s){
        if(s.length!=0){
            old_href=$('#search-a').attr('href');
            $('#search-a').attr('href',old_href.replace(new RegExp('\\?kw\\=[^&]*','gi'),'?kw='+s));
            if(event.key=='Enter'){
                window.location.href=$('#search-a').attr('href');
            }
        }
    }

    $('#fp-search').change(function(){
        if(this.checked==true){
            old_href=$('#search-a').attr('href');
            $('#search-a').attr('href',old_href+'&fp=1');
        }else{
            old_href=$('#search-a').attr('href');
            $('#search-a').attr('href',old_href.replace('&fp=1',''));
        }
    });

    $('#fe-search').change(function(){
        if(this.checked==true){
            old_href=$('#search-a').attr('href');
            $('#search-a').attr('href',old_href+'&fe=1');
        }else{
            old_href=$('#search-a').attr('href');
            $('#search-a').attr('href',old_href.replace('&fe=1',''));
        }
    });

    $('#fp-fe-search').change(function(){
        if(this.checked==true){
            old_href=$('#search-a').attr('href');
            $('#search-a').attr('href',old_href+'&fp_fe=1');
        }else{
            old_href=$('#search-a').attr('href');
            $('#search-a').attr('href',old_href.replace('&fp_fe=1',''));
        }
    });
</script>
{% if is_searched and kw %}
<script type="text/javascript">
    $(document).ready(function(){
        var query=$('#kw-value').text();
        var content_tds=document.getElementsByClassName('content-td');
        var regex=new RegExp(query,'gi');
        for(let i=0;i<content_tds.length;i++){
            content_tds[i].innerHTML=content_tds[i].innerHTML.replace(regex,'<font style="color:red;">$&</font>');
        }
    });
</script>
{% endif %}
{% if is_searched %}
<script type="text/javascript">
    $(document).ready(function(){
    var url=window.location.href;
    // 设置search-a.href为url
    $('#search-a').attr('href',url.replace(new RegExp('&page=[^&]*','gi'),'').replace(new RegExp('&per_page=[^&]*','gi'),''));
    // 选中要搜索的多选框
    var checkbox_kws=url.substring(url.indexOf('&')).split('=1');
    for(let i=0;i<checkbox_kws.length-1;i++){
        switch(checkbox_kws[i].substring(1)){
            case 'fp':
                $('#fp-search').attr('checked','checked');
                break;
            case 'fe':
                $('#fe-search').attr('checked','checked');
                break;
            case 'fp_fe':
                $('#fp-fe-search').attr('checked','checked');
                break;
            default:
                ;
        }
    }
})
</script>
{% endif %}
</div>
{% endblock %}